# Maintainer: Andrea Zagli <andrea.zagli.free@gmail.com>

_realname=phodav
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.4
pkgrel=1
arch=('any')
pkgdesc="A WebDAV server using libsoup (mingw-w64)"
depends=("${MINGW_PACKAGE_PREFIX}-glib2"
         "${MINGW_PACKAGE_PREFIX}-libsoup"
         "${MINGW_PACKAGE_PREFIX}-libxml2")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-asciidoc"
             "${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-gtk-doc")
options=('strip' 'staticlibs')
license=("LGPL 2.1")
url="https://www.gnome.org"
source=(https://download.gnome.org/sources/${_realname}/${pkgver}/${_realname}-${pkgver}.tar.xz
        001-skip-man-for-win.patch
        002-enable-gtk-doc-for-win.patch)
sha256sums=('7dddc2b75e04d0866bb9c9a83028a597ebd73ef4c37bd6ebe1032a870b43b8c3'
            'd5efa5820e37f305f3508baf4948ee8f0611e810a86b24489955c41afedc1595'
            'b24b7bc59c309faf6cf3c47f7e928fbb45273616b20aad49f05a785bdf0f2f68')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}
  # xmlto write in wrong path when pass Windows style directory from meson
  patch -p1 -i ${srcdir}/001-skip-man-for-win.patch
  patch -p1 -i ${srcdir}/002-enable-gtk-doc-for-win.patch
}

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir -p ${srcdir}/build-${MINGW_CHOST} && cd ${srcdir}/build-${MINGW_CHOST}

  ${MINGW_PREFIX}/bin/meson \
    --buildtype=plain \
    -Dgtk_doc=enabled \
    "../${_realname}-${pkgver}"

  ${MINGW_PREFIX}/bin/ninja

}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  DESTDIR="${pkgdir}${MINGW_PREFIX}" ninja install

  local _PRE_WIN="$(cygpath -m ${MINGW_PREFIX})"
  sed -e "s|${_PRE_WIN}|${MINGW_PREFIX}|g" \
    -i ${pkgdir}${MINGW_PREFIX}/lib/pkgconfig/libphodav-2.0.pc

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/lib${_realname}/COPYING"
}
